package com.tensquare.search.service;

import com.tensquare.entity.PageResult;
import com.tensquare.search.dao.ArticleDao;
import com.tensquare.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

/**
 * @author zzb
 * @create 2021/2/22
 */
@Service
public class ArticleService {
    @Autowired
    private ArticleDao articleDao;
    public PageResult<Article> search(String keywords, Integer page, Integer size) {
        //查询出分页对象
        Page<Article> articlePage = articleDao.findByContentAndTitleLike(keywords, keywords, PageRequest.of(page - 1, size));
        return new PageResult<>(articlePage.getTotalElements(),articlePage.getContent());
    }
}
